import uni from '@dcloudio/vite-plugin-uni'
import Components from '@uni-helper/vite-plugin-uni-components'
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
import UniPages from '@uni-helper/vite-plugin-uni-pages'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { defineConfig } from 'vite'
import ViteRestart from 'vite-plugin-restart'

// https://vitejs.dev/config/
export default defineConfig({
  // css: {
  //   preprocessorOptions: {
  //     scss: {
  //       api: 'modern-compiler',
  //     }
  //   }
  // },
  plugins: [
    UnoCSS(),
    Components(
      {
        resolvers: [WotResolver()],
        globs: ['src/components/*/*.vue'],
        dts: 'src/types/components.d.ts',
      },
    ),
    uni.default(),
    ViteRestart({
      restart: ['vite.config.js', 'pages.config.js'], // 监听vite.config.js文件修改,无需重启
    }),
    UniPages({
      // 排除组件文件
      exclude: ['**/components/**/**.*'],
      // 'json5' | 'json' | 'yaml' | 'yml', 具体使用参看文档：https://uni-helper.js.org/vite-plugin-uni-pages
      routeBlockLang: 'yaml',
      dts: 'src/types/uni-pages.d.ts',
      // 配置分包目录
      subPackages: ['src/sub-pages'],
    }),
    AutoImport({
      imports: [
        'vue',
        'uni-app',
        'pinia',
        {
          'uni-mini-router': [
            'createRouter',
            'useRouter',
            'useRoute',
          ],
        },
        {
          'alova/client': [
            'useRequest',
            'usePagination',
          ],
        },
      ],
      eslintrc: {
        enabled: true, // Default `false`
        filepath: 'src/types/.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
      dts: 'src/types/auto-import.d.ts',
      vueTemplate: true,
    }),
  ],
})
